using System;
using BitMango;
using TMPro;
using UnityEngine;

public class StarterPackPopupHandler : MonoBehaviour, IPopupWnd, IHandlerBase
{
	public void DoDataExchange()
	{
	}

	public void OnEnterPopup(object param)
	{
		this.starterInfo = (StarterInfo)param;
		this.OnChangeTime(this.starterInfo.GetStarterTime());
		StarterInfo starterInfo = this.starterInfo;
		starterInfo.OnChangeTime = (Action<string>)Delegate.Combine(starterInfo.OnChangeTime, new Action<string>(this.OnChangeTime));
	}

	public void OnLeavePopup()
	{
		StarterInfo starterInfo = this.starterInfo;
		starterInfo.OnChangeTime = (Action<string>)Delegate.Remove(starterInfo.OnChangeTime, new Action<string>(this.OnChangeTime));
	}

	private void OnChangeTime(string time)
	{
		this.starterTime.text = time;
	}

	private void OnClickStarterPack()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		if (Wallet.GetItemCount("starterpack") > 0)
		{
			return;
		}
		ShopItem shopItemByID = Context.UncleBill.GetShopItemByID("starterpack");
		Scene.Lock("Loading");
		//StoreService.ProcessBuyItem(shopItemByID, delegate(bool succese)
		//{
		//	Scene.Unlock();
		//	if (succese)
		//	{
		//		this.BuyLog("starterpack");
		//		Scene.ClosePopup("StarterPackPopup", true);
		//	}
		//});
	}

	private void OnClickClose()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		Scene.ClosePopup("StarterPackPopup", false);
	}

	private void OnEscape()
	{
		Scene.ClosePopup("StarterPackPopup", false);
	}

	private void BuyLog(string name)
	{
		DateTime d = DateTime.UtcNow;
		if (PlayerPrefs.HasKey("installed"))
		{
			d = DateTime.Parse(PlayerPrefs.GetString("installed"));
		}
		DWATTHelper.logEvent("BuyItemDay", new object[]
		{
			name,
			(DateTime.Now - d).Days
		});
	}

	[SerializeField]
	private tk2dCamera cam;

	[SerializeField]
	private GameObject curtain;

	public TextMeshPro starterTime;

	private StarterInfo starterInfo;
}
